package com.soul.bootribbon.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/ribbon")
public class RibbonController {

    @Autowired
    private RestTemplate restTemplate;

    /*@Autowired
    private LoadBalancerClient loadBalancerClient;*/

    @GetMapping("/index")
    public String ribbon(){
        /*String forObject = restTemplate.getForObject("http://localhost:8100/say/hello", String.class);
        System.out.println(forObject);

        ServiceInstance choose = loadBalancerClient.choose("eureka-client");
        String s = new RestTemplate().getForObject("http://" + choose.getHost() + ":" + choose.getPort() + "/say/hello", String.class);
        System.out.println(s);*/

        String s = restTemplate.getForObject("http://eureka-client/say/hello", String.class);
        System.out.println("=======================================\n"+s);
        return s;
    }
}
